import {Card, WarPower, Weapon} from "@/js/card";
import {SoulMagic, SoulMark} from "@/js/soulMagic";
import {ElementClass} from "@/js/elementMagic";
import {parser as xiParser} from "xijs"

const Parser = {
    jsonToCard(json) {
        try {
            return Card(xiParser.parse(json));
        }catch (e){
            return '读取失败'
        }
    },
    cardToJson(card){
        return xiParser.stringify(card.data)
    },
    cardListToJson(cardList){
        let cardListData=[]
        for (const card of cardList) {
            cardListData.push(card.data)
        }
        return xiParser.stringify(cardListData)
    },
    JsonToCardList(json){
        let cardDataList=xiParser.parse(json)
        console.log(cardDataList)
        let cardList=[]
        for (const cardData of cardDataList) {
            cardList.push(Card(cardData))
        }
        return cardList
    },
    exampleCard() {
        return Card({
            name: "示例",
            sex: "男",
            race: "人族",
            hometown: "中心城",
            fame: "50",
            gold: "50",
            ap: "4",
            armor: "10",
            resistance: "70",
            HP: {
                value: "30",
                max: "30",
                doubleMax: "30",
                status: "健康"
            },
            MP: {
                value: "30",
                max: "30",
                doubleMax: "30",
                status: "充盈"
            },
            attribute: {
                pow: "50",
                spd: "50",
                phy: "50",
                int: "50",
                sol: "50",
                cha: "50"
            },
            fatePoint: "10",
            slotPoint: "5",
            luckPoint: "4",
            item: [
                "something*100", "another thing*52"
            ],
            skill: [
                {
                    name: "示例_1",
                    point: "50"
                }, {
                    name: "示例_2",
                    point: "25"
                }
            ],
            warPowerPoint: "50",
            warPower: [
                WarPower(
                    "示例_1",
                    "3", "1",
                    "this is an example warPower"
                ), WarPower(
                    "示例_2",
                    "4", "3",
                    "this is another example warPower"
                )
            ],
            soulMagicPoint: "70",
            soulMagicLevel: "2",
            soulMagic: [
                SoulMagic(SoulMark(), 'a', '1', '3', 'if you wanner it,you have to take it,that is you already know')
            ],

            elementMagicClass: ElementClass(true),
            elementMagicLevel: "3",
            exMagic: [{
                name: "示例_1",
                level: "0",
                text: "an example exMagic"
            }, {
                name: "示例_2",
                level: "0",
                text: "another example exMagic"
            }],
            otherDescribe: [
                {
                    name: "示例_1",
                    text: "example describe is too loooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"
                }, {
                    name: "示例_2",
                    text: "55"
                }, {
                    name: "示例_3",
                    text: "5"
                }, {
                    name: "示例_4",
                    text: ""
                }
            ],
            story: "oh,he is not real",
            weapon: [
                Weapon(
                    "示例_1",
                    "POW",
                    "1",
                    "1",
                    "3",
                    "3D3",
                    "I wright example 16 times now,you know what is this text meaning"
                ), Weapon(
                    "示例_2",
                    "SPD",
                    "1",
                    "1",
                    "3",
                    "3D3",
                    "I wright example 17 times now,you know what is this text meaning"
                )
            ]
        })
    },
    emptyCard(){
        return Card({
            name: "",
            sex: "",
            race: "",
            hometown: "",
            fame: "",
            gold: "",
            ap: "",
            armor: "",
            resistance: "",
            HP: {
                value: "",
                max: "",
                doubleMax: "",
                status: "健康"
            },
            MP: {
                value: "",
                max: "",
                doubleMax: "",
                status: "充盈"
            },
            attribute: {
                pow: "",
                spd: "",
                phy: "",
                int: "",
                sol: "",
                cha: ""
            },
            fatePoint: "",
            slotPoint: "",
            luckPoint: "",
            item: [],
            skill: [],
            warPowerPoint: "",
            warPower: [],
            soulMagicPoint: "",
            soulMagicLevel: "",
            soulMagic: [],
            elementMagicClass: ElementClass(),
            elementMagicLevel: "",
            exMagic: [{}],
            otherDescribe: [],
            story: "",
            weapon: []})
    }
}

export default Parser
